package com.xhs.design.factory;

import com.xhs.service.AbstractLevelHandler;
import com.xhs.service.impl.HandlerOneLevelImpl;
import com.xhs.service.impl.HandlerThreeLeveImpl;
import com.xhs.service.impl.HandlerTwoLevelImpl;
import com.xhs.utils.ContextUtils;

/**
 * @desc:
 * @projectName: tools-parent
 * @author: xhs
 * @date: 2022/12/5 10:33
 * @version: JDK 1.8
 */
public class FactoryHandler {

    /**
     * 设置下一个LevelHandler
     *
     * @return
     */
    public static AbstractLevelHandler getLevelHandler() {
        HandlerOneLevelImpl oneLevelHandler = ContextUtils.getBean("handlerOneLevelImpl", HandlerOneLevelImpl.class);
        HandlerTwoLevelImpl twoLevelHandler = ContextUtils.getBean("handlerTwoLevelImpl", HandlerTwoLevelImpl.class);
        HandlerThreeLeveImpl threeLevelHandler = ContextUtils.getBean("handlerThreeLeveImpl", HandlerThreeLeveImpl.class);
        oneLevelHandler.setNextLevelHandler(twoLevelHandler);
        twoLevelHandler.setNextLevelHandler(threeLevelHandler);
        return oneLevelHandler;
    }
}
